package html.states.home.notifications;
import data.Message;
import html.util.Container;
import js.Dom;

/**
 * ...
 * @author Felipe Manga
 */

class Notification extends Container
{
	var items:Array<Message>;
	var type:String;
	var label:HtmlDom;
	
	public function new( type:String ) 
	{
		super( "notifications." + type );
		this.type = type;
		this.label = this.get("label");
		this.items = new Array<Message>();
		
		this.addChild( new Dropdown( this.element.id ) );
		this.label.addEventListener("click", onClickElement);
		this.label.innerHTML = "0";
	}
	
	function onClickElement( e:Event ):Void
	{
		if ( e.target != this.label ) return;
		this.signalDown("toggleDropdownVisible", []);
	}
	
	@slot function newMessage( type:String, msg:Message ):Void
	{
		if ( this.type != type ) return;
		items.push( msg );
		label.innerHTML = Std.string(items.length);
		
		this.signalDown( "dropdownAddItem", [msg] );
	}
}